import util from '@/network/common/util.js';
import $ from 'jquery'

let postCfg = {
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    transformRequest: function (data) {
        return $.param(data)
    }
}
let api = {
    'getDimensions'         : '/room/v1/getDimensions', //获取影厅类型维度列表
    'getDimensionDetails'   : '/room/v1/getDimensionDetails', //获取影厅类型维度详情
    'getRoomStatusList'     : '/room/v1/getRoomStatusList', //获取影厅状态列表
    'getRoomList'           : '/room/v1/getRoomList', //获取影厅列表
    'getRoomInfo'           : '/room/v1/getRoomInfo', //获取影厅详情
    'getRoomBookList'       : '/room/v1/getRoomBookList', //获取指定影厅预定列表
    'getUserInfoByCard'     : '/room/v1/getUserInfoByCard', //通过会员卡获取会员信息
    'getUserInfoByTel'      : '/room/v1/getUserInfoByTel', //通过手机号获取会员信息
    'getFilmList'           : '/room/v1/getFilmList', //获取电影列表
    'roomLock'              : '/room/v1/roomLock', //锁定影厅
    'roomUnLock'            : '/room/v1/roomUnLock', //解锁影厅
    'createOrder'           : '/room/v1/createOrder', //创建订单
    'createTimeOrder'       : '/room/v1/createTimeOrder', //创建续时订单
    'createChangeOrder'     : '/room/v1/createChangeOrder', //创建转厅订单
    'setOrderAuthPrice'     : '/room/v1/setOrderAuthPrice', //订单设置权限价格
    'orderPayWay'           : '/room/v1/orderPayWay', //支付方式
    'roomOpen'              : '/room/v1/roomOpen', //影厅开厅
    'roomCostDetail'        : '/room/v1/roomCostDetail', //影厅消费详情
    'roomTodayPriceList'    : '/room/v1/roomTodayPriceList', //影厅价格列表
    'roomGoodsList'         : '/room/v1/roomGoodsList', //影厅酒水消费列表
    'roomSettle'            : '/room/v1/roomSettle', //影厅结算列表
    'roomFree'              : '/room/v1/roomFree', //影厅置闲
    'roomRepair'            : '/room/v1/roomRepair', //影厅维修
    
}
let res = {};
function getDimensions () {
    let p = new Promise(function (resolve, reject) {
        util.ajax.post(api.getDimensions, {}, postCfg).then(function(res) {
            resolve(res);
        }, function(error) {
            reject(error);
        });
    });
    return p;
}
function getDimensionDetails (params) {
    let p = new Promise(function (resolve, reject) {
        util.ajax.post(api.getDimensionDetails, {
            dimensionId: params.dimensionId,
            scales: params.scales,
            status: params.status
        }, postCfg).then(function(res) {
            resolve(res);
        }, function(error) {
            reject(error);
        });
    });
    return p;
}
function getRoomStatusList (scales) {
    let p = new Promise(function (resolve, reject) {
        util.ajax.post(api.getRoomStatusList, {
            scales: scales
        }, postCfg).then(function(res) {
            resolve(res);
        }, function(error) {
            reject(error);
        });
    });
    return p;
}
function getRoomList (params) {
    let p = new Promise(function (resolve, reject) {
        util.ajax.post(api.getRoomList, {
            scales: params.scales,
            status: params.status,
        }, postCfg).then(function(res) {
            resolve(res);
        }, function(error) {
            reject(error);
        });
    });
    return p;
}
function getRoomInfo (id) {
    let p = new Promise(function (resolve, reject) {
        util.ajax.post(api.getRoomInfo, {
            id: id
        }, postCfg).then(function(res) {
            resolve(res);
        }, function(error) {
            reject(error);
        });
    });
    return p;
}
function getRoomBookList (id) {
    let p = new Promise(function (resolve, reject) {
        util.ajax.post(api.getRoomBookList, {
            id: id
        }, postCfg).then(function(res) {
            resolve(res);
        }, function(error) {
            reject(error);
        });
    });
    return p;
}
function getUserInfoByCard (cardNo) {
    let p = new Promise(function (resolve, reject) {
        util.ajax.post(api.getUserInfoByCard, {
            cardNo: cardNo
        }, postCfg).then(function(res) {
            resolve(res);
        }, function(error) {
            reject(error);
        });
    });
    return p;
}
function getUserInfoByTel (phoneNum) {
    let p = new Promise(function (resolve, reject) {
        util.ajax.post(api.getUserInfoByTel, {
            phoneNum: phoneNum
        }, postCfg).then(function(res) {
            resolve(res);
        }, function(error) {
            reject(error);
        });
    });
    return p;
}
function getFilmList (type) {
    let p = new Promise(function (resolve, reject) {
        util.ajax.post(api.getFilmList, {
            type: type
        }, postCfg).then(function(res) {
            resolve(res);
        }, function(error) {
            reject(error);
        });
    });
    return p;
}
function roomLock (id) {
    let p = new Promise(function (resolve, reject) {
        util.ajax.post(api.roomLock, {
            id: id
        }, postCfg).then(function(res) {
            resolve(res);
        }, function(error) {
            reject(error);
        });
    });
    return p;
}
function roomUnLock (id) {
    let p = new Promise(function (resolve, reject) {
        util.ajax.post(api.roomUnLock, {
            id: id
        }, postCfg).then(function(res) {
            resolve(res);
        }, function(error) {
            reject(error);
        });
    });
    return p;
}
function createOrder (params) {
    let p = new Promise(function (resolve, reject) {
        util.ajax.post(api.createOrder, {
            id: params.id,
            phoneNum: params.phoneNum,
            name: params.name,
            isMember: params.isMember,
            memberId: params.memberId,
            cardNo: params.cardNo,
            number: params.number,
            isBook: params.isBook,
            bookNo: params.bookNo,
            hours: params.hours,
            movie: params.movie
        }, postCfg).then(function(res) {
            resolve(res);
        }, function(error) {
            reject(error);
        });
    });
    return p;
}
function createTimeOrder (params) {
    let p = new Promise(function (resolve, reject) {
        util.ajax.post(api.createTimeOrder, {
            id: params.id,
            hours: params.hours
        }, postCfg).then(function(res) {
            resolve(res);
        }, function(error) {
            reject(error);
        });
    });
    return p;
}
function createChangeOrder (params) {
    let p = new Promise(function (resolve, reject) {
        util.ajax.post(api.createChangeOrder, {
            id: params.id,
            newId: params.newId,
        }, postCfg).then(function(res) {
            resolve(res);
        }, function(error) {
            reject(error);
        });
    });
    return p;
}
function setOrderAuthPrice (params) {
    let p = new Promise(function (resolve, reject) {
        util.ajax.post(api.setOrderAuthPrice, {
            id: params.id,
            authMoney: params.authMoney,
            authPhoneNum: params.authPhoneNum
        }, postCfg).then(function(res) {
            resolve(res);
        }, function(error) {
            reject(error);
        });
    });
    return p;
}
function orderPayWay (params) {
    let p = new Promise(function (resolve, reject) {
        util.ajax.post(api.orderPayWay, {
            id: params.id,
            payWay: params.payWay,
            getMoney: params.getMoney,
            isHand: params.isHand,
            handRoomId: params.handRoomId,
            password: params.password
        }, postCfg).then(function(res) {
            resolve(res);
        }, function(error) {
            reject(error);
        });
    });
    return p;
}
function roomOpen (params) {
    let p = new Promise(function (resolve, reject) {
        util.ajax.post(api.roomOpen, {
            id: params.id,
            oid: params.oid,
        }, postCfg).then(function(res) {
            resolve(res);
        }, function(error) {
            reject(error);
        });
    });
    return p;
}
function roomCostDetail (id) {
    let p = new Promise(function (resolve, reject) {
        util.ajax.post(api.roomCostDetail, {
            id: id,
        }, postCfg).then(function(res) {
            resolve(res);
        }, function(error) {
            reject(error);
        });
    });
    return p;
}
function roomTodayPriceList (id) {
    let p = new Promise(function (resolve, reject) {
        util.ajax.post(api.roomTodayPriceList, {
            id: id,
        }, postCfg).then(function(res) {
            resolve(res);
        }, function(error) {
            reject(error);
        });
    });
    return p;
}
function roomGoodsList (id) {
    let p = new Promise(function (resolve, reject) {
        util.ajax.post(api.roomGoodsList, {
            id: id,
        }, postCfg).then(function(res) {
            resolve(res);
        }, function(error) {
            reject(error);
        });
    });
    return p;
}
function roomSettle (id) {
    let p = new Promise(function (resolve, reject) {
        util.ajax.post(api.roomSettle, {
            id: id,
        }, postCfg).then(function(res) {
            resolve(res);
        }, function(error) {
            reject(error);
        });
    });
    return p;
}
function roomFree (id) {
    let p = new Promise(function (resolve, reject) {
        util.ajax.post(api.roomFree, {
            id: id,
        }, postCfg).then(function(res) {
            resolve(res);
        }, function(error) {
            reject(error);
        });
    });
    return p;
}
function roomRepair (id) {
    let p = new Promise(function (resolve, reject) {
        util.ajax.post(api.roomRepair, {
            id: id,
        }, postCfg).then(function(res) {
            resolve(res);
        }, function(error) {
            reject(error);
        });
    });
    return p;
}

export default {
    getDimensions,
    getDimensionDetails,
    getRoomStatusList,
    getRoomList,
    getRoomInfo,
    getRoomBookList,
    getUserInfoByCard,
    getUserInfoByTel,
    getFilmList,
    roomLock,
    roomUnLock,
    createOrder,
    createTimeOrder,
    createChangeOrder,
    setOrderAuthPrice,
    orderPayWay,
    roomOpen,
    roomCostDetail,
    roomTodayPriceList,
    roomGoodsList,
    roomSettle,
    roomFree,
    roomRepair
}